package arraylistTest;

import java.util.*;

public class Test {
    public static void main(String[] args) {
//        List<String> list1 = new LinkedList<>();
//        ArrayList<String> list2 = new ArrayList<>(list1);
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        list1.add(4);
        System.out.println(list1.remove(0));
        //System.out.println(list1.remove(new Integer(3)));

        //1 for循环遍历
        for(int i = 0; i <list1.size(); i++){
            System.out.print(list1.get(i) + " ");
        }
        System.out.println();
        //2 for each循环遍历
        for(Integer integer : list1){
            System.out.print(integer + " ");
        }
        System.out.println();
        //3 迭代器
            //从前往后  next
        Iterator<Integer> it = list1.iterator();
        while (it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();
            //从后往前  previous
        ListIterator<Integer> it1 = list1.listIterator(list1.size());
        while (it1.hasPrevious()){
            System.out.print(it1.previous() + " ");
        }
        System.out.println();
    }

    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList(10);
        myArrayList.add(1);
        myArrayList.add(22);
        myArrayList.add(3);
        myArrayList.add(5);
        myArrayList.display();
        System.out.println(myArrayList.indexOf(4));
        System.out.println(myArrayList.contains(22));
        System.out.println(myArrayList.get(1));
        myArrayList.remove(22);
        myArrayList.display();
        myArrayList.clear();
        myArrayList.display();
//        myArrayList.add(6,3);
    }

}
